import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createApp } from 'vue'
import Avue from '@smallwei/avue'
import '@smallwei/avue/lib/index.css'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import AWS from 'aws-sdk';
// key AKIA3FLD4WZSP52YERIA
// sercret PQXT0bzWVZu1beaAdnrpBIR2cdzlekDH3v/RcWnQ
import aws_cfg from "@/utils/aws"
// h5client
// 引入echarts
const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
AWS.config.update({
    accessKeyId: 'AKIA3FLD4WZSP52YERIA',
    secretAccessKey: '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',
    region: 'eu-central-1'
});
const s3 = new AWS.S3();
window.AWS = s3;

const bucketName = 'h5client';
const uploadToS3 = (file) => {
    console.log('=====sfile')
    return new Promise((resolve, reject) => {
        const params = {
            Bucket: bucketName,
            Key: file.name,
            Body: file,
            ContentType: file.type
        };

        s3.upload(params, (err, data) => {
            if (err) {
                console.error('Upload failed:', err);
                reject(err);
            } else {
                console.log('Upload successful:', data);
                resolve(data.Location);
            }
        });
    });
};
console.log('s3===',s3)
aws_cfg.uploadToS3 = uploadToS3
console.log('aws_cfg',aws_cfg)
app.use(router).use(store).use(ElementPlus, {
    locale: zhCn,
}).use(Avue, {
    ali: {
        region: 'hongkong',
        endpoint: 'oss-cn-hongkong.aliyuncs.com',
        accessKeyId: 'LTAI5tRC85CdqZBhEFFnrJBn',
        accessKeySecret: 'wA0A3BJUerPvCk6KHZRejL1qD9wzv9',
        bucket: 'chuangmd',
    },
    s3:{
        accessKeyId: 'AKIA3FLD4WZSP52YERIA',
        secretAccessKey:'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',
        region:'eu-central-1',
        bucket:'h5client'
    },
    axios,
}).mount('#app')
